//
//  JNSessionManager.m
//  JNNetEestNews
//
//  Created by Jyougen on 2017/3/10.
//  Copyright © 2017年 Jyougen. All rights reserved.
//

#import "JNSessionManager.h"

@implementation JNSessionManager


+ (instancetype)sharedManager{
    
    static JNSessionManager * manager;
    static dispatch_once_t once;
    
    dispatch_once(&once, ^{
        manager = [[JNSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://c.m.163.com/nc/article/list/"]];
    });
    
    return manager;
}

- (void)reqestWithRequestType:(RequestType)requestType andURLStr:(NSString *)URLStr andSuccessBlock:(void(^)(id response))successBlock andFailureBlock:(void(^)(NSError * error))failureBlock{
    
    if (requestType == RequestTypeGet){
        
        [self GET:URLStr parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            successBlock(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            failureBlock(error);
        }];
        
    }else{
        
        [self POST:URLStr parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
    
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            successBlock(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            failureBlock(error);
        }];
        
    }
    
}

@end
